/**
 * Created by liliang on 2018/4/24.
 */
$(function () {
    var shopAddUrl = '/shop/register';
    var shopGetUrl = '/shop/shopList';
    alert(shopAddUrl);
    function getShop() {
        $.getJSON(shopGetUrl, function (data) {
            // if (data.success) {
            //     var tempHtml = '';
            //     var tempAreaHtml = '';
            //     data.shopCategoryList.map(function (item,index) {
            //         tempHtml += '<option id="'+item.id+'">'
            //         + item.name + '</option>';
            //     });
            //     data.areaList.map(function (item,index) {
            //         tempAreaHtml += '<option id="'+item.id+'">'
            //         + item.name +'</option>';
            //     });
            //     $('#shopCategory').html(tempHtml);
            //     $('#area').html(tempAreaHtml);
            // }
        })
    }

    $('#submit').click(function () {
        var shop = {};
        // shop.shopCategory = {
        //   id : $('#shopCategory').find('option').not(function () {
        //       return !this.selected;
        //   }).data('id')
        // };
        shop.name = $('#shopName').val();
        shop.shopAddr = $('#shopAddr').val();
        shop.shopDesc = $('#shopDesc').val();
        shop.phone = $('#phone').val();
        shop.priority = $('#priority').val();
        var shopImg = $('#shopImg')[0].files[0];
        var formData = new FormData();
        formData.append('shopImg', shopImg);
        formData.append('shop', JSON.stringify(shop));
        $.ajax({
            url: shopAddUrl,
            type: 'POST',
            data: formData,
            cache: false,
            processData: false,
            contentType:false,
            dataType:"json",
            success: function (data) {
                if (data.success) {
                    alert('成功');
                }
            }
        });
    });
});